package com.ydd.mapper;

import com.ydd.dto.LoginDTO;
import com.ydd.dto.SysUserDTO;
import com.ydd.entity.SysUser;
import com.ydd.vo.SysUserVO;
import org.apache.ibatis.annotations.Delete;
import com.ydd.entity.YddUser;
import org.apache.ibatis.annotations.Select;
import com.github.pagehelper.Page;
import com.ydd.annotation.AutoFill;
import com.ydd.dto.SysUserPageQueryDTO;
import com.ydd.entity.SysUser;
import com.ydd.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;
import java.util.List;

@Mapper

public interface SysUserMapper{

    @Select("select * from sys_user where login_name=#{loginName}")
    SysUser selectByUser(LoginDTO loginDTO);

    @Select("select * from sys_user where id=#{id}")
    SysUser selectById(String id);

    /**
     * 动态条件查询数量
     * @param user
     * @return
     */
 /*   @Select("select count(*) from sys_user where role_id=#{rolueId}")*/
    Integer countByRoleId(SysUser user);



    /**
     * 查询sysUser分页对象
     * @param sysUserPageQueryDTO
     * @return
     */
    Page<SysUserVO> pageQuery(SysUserPageQueryDTO sysUserPageQueryDTO);


    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into sys_user values (#{id},#{loginName},#{password}," +
            "#{name},#{email},#{phone},#{loginIp},#{loginDate}," +
            "#{createDate},#{updateDate},#{delFlag},#{roleId}," +
            "#{status},#{defaultData});")
    void insert(SysUser sysUser);

    @Delete("delete from sys_user where id = #{id};")
    void deleteById(String id);

    /**
     * 管理员修改
     * @param sysUser
     */
    void update(SysUser sysUser);

    @Select("select * from sys_user where create_date>=#{todayMinTime}")
    YddUser[] getNewUser(LocalDateTime todayMinTime);

    @Select("select * from sys_user where id=#{UserId}")
    YddUser getUserById(String UserId);

    @Select("select * from sys_user where login_name = #{loginName}")
    SysUser selectByLoginName(SysUserDTO sysUserDTO);

    @Select("select * from sys_user")
    List<SysUserVO> getAll();
}
